package st.business.tepth.business.visitor.visitorwork.work.detail;

import java.util.ArrayList;
import java.util.List;

import st.business.tepth.business.visitor.visitorwork.entity.WorkDetailBean;
import st.business.tepth.config.ItemFields;
import st.shadow.library.ui.recycler.MultipleItemEntity;

/**
 * @author zhangyu
 * @date 2019/6/6
 */
public class DataConvert {
    public List<MultipleItemEntity> convertMaintain(ArrayList<WorkDetailBean.MaintainBean> maintainBeans) {
        List<MultipleItemEntity> list = new ArrayList<>();
        if (maintainBeans != null) {
            for (WorkDetailBean.MaintainBean maintainBean : maintainBeans) {
                list.add(MultipleItemEntity.builder()
                        .setItemType(MaintainAdapter.TYPE_1)
                        .setField("content", maintainBean.getWorkContent())
                        .setField("standard", maintainBean.getWorkStandard())
                        .build());
                List<WorkDetailBean.RepairBean.ProgramBean> programBeans =
                        maintainBean.getProgram();
                if (programBeans != null && !programBeans.isEmpty()) {
                    list.add(MultipleItemEntity.builder()
                            .setItemType(MaintainAdapter.TYPE_2)
                            .build());
                    for (WorkDetailBean.RepairBean.ProgramBean programBean :
                            programBeans) {
                        list.add(MultipleItemEntity.builder()
                                .setItemType(MaintainAdapter.TYPE_3)
                                .setField(ItemFields.ITEM_OBJ, programBean)
                                .build());
                    }
                }
            }
        }
        return list;
    }

    public List<MultipleItemEntity> convertRepair(ArrayList<WorkDetailBean.RepairBean>
                                                          repairBeans) {
        List<MultipleItemEntity> list = new ArrayList<>();
        if (repairBeans != null) {
            for (WorkDetailBean.RepairBean repairBean : repairBeans) {
                list.add(MultipleItemEntity.builder()
                        .setItemType(RepairAdapter.TYPE_1)
                        .setField("repair", repairBean.getRepairPhenomenon())
                        .setField("diagnose", repairBean.getRepairDiagnose())
                        .build());
                List<WorkDetailBean.RepairBean.ProgramBean> programBeans =
                        repairBean.getProgram();
                if (programBeans != null) {
                    for (WorkDetailBean.RepairBean.ProgramBean programBean :
                            programBeans) {
                        list.add(MultipleItemEntity.builder()
                                .setItemType(RepairAdapter.TYPE_2)
                                .setField(ItemFields.ITEM_OBJ, programBean)
                                .build());
                    }
                }
            }
        }
        return list;
    }
}
